<template lang="jade">
div
  h-loader-full(url='loader',:setdata='false')
  h-data-updater
  m-title(icon='add',name='编辑培训课程')
  table.single
    mf-row(name='所属培训学校') {{p.sname + '(' + show[p.school_show] + ')'}}
    mf-row(name='所属培训课程') {{p.culname + '(' + show[p.cultivate_show] + ')'}}
    mf-row(name='培训课期显示位置',v-if='p.sid && p.culid')
      select(v-model='p.show',placeholder='请选择显示位置',v-if='p.school_show == 0 && p.cultivate_show == 0')
        option(value='', selected) 请选择
        option(v-for='(n,i) in show', :value='i') {{n}}
      span(v-if='p.school_show != 0 || p.cultivate_show != 0') {{show[p.show]}}
    mf-row(name='课期名称')
      input(type = 'text',v-model='p.name',placeholder='请填写课程名称')
    mf-row(name='课期开始时间：')
      input(type='datetime-local',v-model='p.class_starttime')
    mf-row(name='课期结束时间：')
      input(type='datetime-local',v-model='p.class_endtime')
    mf-row(name='课期报名截止时间：')
      input(type='datetime-local',v-model='p.apply_endtime')
    mf-row(name='课期往期图片'): mf-upload(uploadid='img', amount='1', project='xiongan', category='logo', :data='p.history_img',@upload_data='text')
    mf-row(name='课程内容')
      textarea#con.editor(style='width: 500px; height: 200px;', v-model='p.content') {{p.content}}
    mf-row(name='培养目标')
      textarea#target.editor(style='width: 500px; height: 200px;', v-model='p.target') {{p.target}}
    mf-row(name='学制')
      textarea#system.editor(style='width: 500px; height: 200px;', v-model='p.system') {{p.system}}
    mf-row
      button(@click='button') 确认提交
</template>

<script>
export default {
	data () {
		return {
      loader:{
        p:'cultivate/semester/list?id=' + this.$query.get('semid'),
      },
      p:[],
      ishome:['否','是'],
      show:['两端显示','用户端','企业端'],
		}
	},
	methods: {
    loadAfter(res){
      this.p = res.p[0][0]
      this.p.history_img = this.p.history_img.split('|')
      this.p.class_starttime = new Date(this.p.class_starttime * 1000).format("yyyy-MM-ddThh:mm")
      this.p.class_endtime = new Date(this.p.class_endtime * 1000).format("yyyy-MM-ddThh:mm")
      this.p.apply_endtime = new Date(this.p.apply_endtime * 1000).format("yyyy-MM-ddThh:mm")
      con.sync()
      target.sync()
      system.sync()
      con.html(this.p.content);
      target.html(this.p.target);
      system.html(this.p.system);
		},
    text(data){
			this.p.history_img = data
		},
    button(){
      con.sync()
      target.sync()
      system.sync()
      this.p.content = this.$dom.id('con').value
      this.p.target = this.$dom.id('target').value
      this.p.system = this.$dom.id('system').value
      if(this.p.show !=0 && this.p.show !=1 && this.p.show !=2){
        this.$msg.error('请选择显示位置!')
        return
      }
      if(this.p.name == ''){
        this.$msg.error('请填写课期名称!')
        return
      }
      if(this.p.history_img.length == 0 ){
        this.$msg.error('请上传图片!')
        return
      }
      if(this.p.culid == ''){
        this.$msg.error('请选择所属培训课程!')
        return
      }
      if(this.p.class_starttime == ''){
        this.$msg.error('请填写课期开始时间!')
        return
      }
      if(this.p.class_starttime == ''){
        this.$msg.error('请填写课期结束时间!')
        return
      }
      if(this.p.class_starttime == ''){
        this.$msg.error('请填写课期报名结束时间!')
        return
      }
      if( this.p.content == ''){
        this.$msg.error('请填写课期内容!')
        return
      }
      if(this.p.target == ''){
        this.$msg.error('请填写培养目标!')
        return
      }
      if( this.p.system == ''){
        this.$msg.error('请填写学制!')
        return
      }
      this.$ajax.put('cultivate/edit/semester',this.p,(res)=>{
        this.$msg.success(res.message)
        setTimeout("window.location.reload()",1000)
      },(res)=>{
        this.$msg.error(res.message)
      })
    }
	}
}
</script>